﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using DSPL.Contracts;
using DSPL.Contracts.Common;
using DSPL.Contracts.Interfaces;
using DSPL.Finac.View;

namespace DSPL.Finac.Common
{
    public class MessageService : IMessageService
    {
        #region IMessageService Members

        public MessageBoxResult ShowMessage(MessageText messageText, string messageGeneratedForm, MessageType messageType = MessageType.None)
        {
            MessageBoxResult messageResult;

            switch (messageType)
            {
                case MessageType.ErrOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Error);
                    break;

                case MessageType.InfoOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case MessageType.QuizOKCancel:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OKCancel, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNo:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.YesNo, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNoCancel:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    break;

                case MessageType.WarningOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Warning);
                    break;

                default:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName + " - " + messageGeneratedForm);
                    break;

            }
            return messageResult;
        }

        public MessageBoxResult ShowMessage(string messageText, string messageGeneratedForm, MessageType messageType = MessageType.None)
        {
            MessageBoxResult messageResult;
            
            switch (messageType)
            {
                case MessageType.ErrOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Error);
                    break;

                case MessageType.InfoOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case MessageType.QuizOKCancel:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OKCancel, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNo:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.YesNo, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNoCancel:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    break;

                case MessageType.WarningOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Warning);
                    break;

                default:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm);
                    break;

            }
            return messageResult;
        }
        
        public MessageBoxResult ShowMessage(MessageText messageText, MessageType messageType = MessageType.None)
        {
            MessageBoxResult messageResult;
            
            switch (messageType)
            {
                case MessageType.ErrOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
                    break;

                case MessageType.InfoOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case MessageType.QuizOKCancel:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.OKCancel, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNo:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.YesNo, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNoCancel:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    break;

                case MessageType.WarningOK:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Warning);
                    break;

                default:
                    messageResult = MessageBox.Show(StringEnum.GetStringValue(messageText), GlobalVariables.ApplicationName);
                    break;

            }
            return messageResult;
        }

        public MessageBoxResult ShowMessage(string messageText, MessageType messageType = MessageType.None)
        {
            MessageBoxResult messageResult;
            
            switch (messageType)
            {
                case MessageType.ErrOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
                    break;

                case MessageType.InfoOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case MessageType.QuizOKCancel:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.OKCancel, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNo:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.YesNo, MessageBoxImage.Question);
                    break;

                case MessageType.QuizYesNoCancel:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    break;

                case MessageType.WarningOK:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Warning);
                    break;

                default:
                    messageResult = MessageBox.Show(messageText, GlobalVariables.ApplicationName);
                    break;

            }
            return messageResult;
        }

        public void ShowException(string exceptionMessage, string methodName)
        {
            string MessageText;
            MessageText = "Error occurred at : " + methodName + "\n" + "Error : " + exceptionMessage;
            MessageBox.Show(MessageText, GlobalVariables.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Error);
        }

        public void ShowException(string exceptionMessage, string methodName, string messageGeneratedForm)
        {
            string MessageText;
            MessageText = "Error occurred at : " + methodName + "\n" + "Error : " + exceptionMessage;
            MessageBox.Show(MessageText, GlobalVariables.ApplicationName + " - " + messageGeneratedForm, MessageBoxButton.OK, MessageBoxImage.Error);
        }

        public void ShowPopupWindow(dynamic viewModel)
        {
            PoupWindow popupWindow = new PoupWindow();
            popupWindow.popupContent.Content = viewModel;
            popupWindow.ShowDialog();
        }

        public void ShowWindow(dynamic viewModel)
        {
            try
            {
                PoupWindow popupWindow = new PoupWindow();
                popupWindow.popupContent.Content = viewModel;
                popupWindow.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
        }

        public void ShowReport(dynamic viewModel)
        {
            ReportWindow reportWindow = new ReportWindow();
            reportWindow.popupContent.Content = viewModel;
            reportWindow.Show();
        }

        #endregion
    }

    

}
